#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>

ros::Publisher pub;

void scanCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
{
    sensor_msgs::LaserScan flipped = *msg;

    // 翻转角度
    flipped.angle_min = msg->angle_max;
    flipped.angle_max = msg->angle_min;
    flipped.angle_increment = -msg->angle_increment;

    // 翻转 ranges 和 intensities
    std::reverse(flipped.ranges.begin(), flipped.ranges.end());
    std::reverse(flipped.intensities.begin(), flipped.intensities.end());

    pub.publish(flipped);
}

int main(int argc, char** argv)
{
    ros::init(argc, argv, "laser_node");
    ros::NodeHandle nh;

    ros::Subscriber sub = nh.subscribe("scan/raw", 10, scanCallback);
    pub = nh.advertise<sensor_msgs::LaserScan>("scan", 10);

    ros::spin();
    return 0;
}